Avoid xen crash if there is no VMX support. If a platform
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 30 Dec 2005 16:07:34 +0000 (17:07 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 30 Dec 2005 16:07:34 +0000 (17:07 +0100)
doesn't support VMX, creating VMX domain will crash xen
HV.

Signed-off-by: Xin Li <xin.b.li@intel.com>
tools/libxc/xc_vmx_build.c
tools/python/xen/xend/image.py
xen/arch/x86/domain.c

index 9d0fbc18d5606a01d2ebe88d93c7dd8b90f3ba2c..e3a6c88b6ea2546cd3b387e97cfd3c48c545f50e 100644 (file)
@@ -574,29 +574,6 @@ static int setup_guest(int xc_handle,
     return -1;
 }
 
-#define VMX_FEATURE_FLAG 0x20
-
-static int vmx_identify(void)
-{
-    int eax, ecx;
-
-    __asm__ __volatile__ (
-#if defined(__i386__)
-                          "push %%ebx; cpuid; pop %%ebx"
-#elif defined(__x86_64__)
-                          "push %%rbx; cpuid; pop %%rbx"
-#endif
-                          : "=a" (eax), "=c" (ecx)
-                          : "0" (1)
-                          : "dx");
-
-    if (!(ecx & VMX_FEATURE_FLAG)) {
-        return -1;
-    }
-
-    return 0;
-}
-
 int xc_vmx_build(int xc_handle,
                  uint32_t domid,
                  int memsize,
@@ -613,10 +590,18 @@ int xc_vmx_build(int xc_handle,
     unsigned long nr_pages;
     char         *image = NULL;
     unsigned long image_size;
+    xen_capabilities_info_t xen_caps;
+
+    if ( (rc = xc_version(xc_handle, XENVER_capabilities, &xen_caps)) != 0 )
+    {
+        PERROR("Failed to get xen version info");
+        goto error_out;
+    }
 
-    if ( vmx_identify() < 0 )
+    if ( !strstr(xen_caps, "hvm") )
     {
-        PERROR("CPU doesn't support VMX Extensions");
+        PERROR("CPU doesn't support VMX Extensions or "
+               "CPU VMX Extensions are not turned on");
         goto error_out;
     }
 
index b8ebc7a2aa19d9dbe853681fe75981f632101a1d..94995213fee34f4b44931cea873953419ad36e4b 100644 (file)
@@ -189,6 +189,10 @@ class VmxImageHandler(ImageHandler):
     def configure(self, imageConfig, deviceConfig):
         ImageHandler.configure(self, imageConfig, deviceConfig)
 
+        info = xc.xeninfo()
+        if not 'hvm' in info['xen_caps']:
+            raise VmError("vmx: not an Intel VT platform, we stop creating!")
+
         self.dmargs = self.parseDeviceModelArgs(imageConfig, deviceConfig)
         self.device_model = sxp.child_value(imageConfig, 'device_model')
         if not self.device_model:
index 850b88d1414a81419c5e166e01920302de223c0d..2c89207e1bdf612400804550cc484be112ee8b02 100644 (file)
@@ -35,7 +35,6 @@
 #include <xen/console.h>
 #include <xen/elf.h>
 #include <asm/vmx.h>
-#include <asm/vmx_vmcs.h>
 #include <asm/msr.h>
 #include <asm/physdev.h>
 #include <xen/kernel.h>
@@ -348,6 +347,8 @@ int arch_set_info_guest(
              ((c->user_regs.ss & 3) == 0) )
             return -EINVAL;
     }
+    else if ( !hvm_enabled )
+        return -EINVAL;
 
     clear_bit(_VCPUF_fpu_initialised, &v->vcpu_flags);
     if ( c->flags & VGCF_I387_VALID )